#include "ASRPro.h"

ASRPro::ASRPro(HardwareSerial *serial, int rxPin, int txPin, int wakePin) {
    _serial = serial;
    _rxPin = rxPin;
    _txPin = txPin;
    _wakePin = wakePin;
}

void ASRPro::begin(long baud) {
    _serial->begin(baud, SERIAL_8N1, _rxPin, _txPin);
    delay(200);

    // 如果有唤醒脚，拉高
    if (_wakePin >= 0) {
        pinMode(_wakePin, OUTPUT);
        digitalWrite(_wakePin, HIGH);
    }

    Serial.println("ASRPro initialized.");
    sendCommand("version");
}

void ASRPro::sendCommand(const String &cmd) {
    Serial.print("Send -> ");
    Serial.println(cmd);
    _serial->println(cmd);
}

void ASRPro::checkResponse() {
    while (_serial->available()) {
        String resp = _serial->readStringUntil('\n');
        resp.trim();
        if (resp.length() > 0) {
            Serial.print("ASR-PRO Response: ");
            Serial.println(resp);
        }
    }
}